﻿using System;
using _5E.WebInfrastructure.Security;
using Melee.Infrastructure.Configuration;

namespace Melee.Controller.Storage
{
    public class UserCookie
    {
        private DateTime m_lastModifyDate = DateTime.Now;

        private Guid m_LoginId = Guid.Empty;
        public Guid LoginId
        {
            get { return m_LoginId; }
            set { m_LoginId = value; }
        }

        private string m_LoginName = null;
        public string LoginName
        {
            get { return m_LoginName; }
            set { m_LoginName = value; }
        }

        private string m_UserName = null;
        public string UserName
        {
            get { return m_UserName; }
            set { m_UserName = value; }
        }

        public void Save()
        {
            CustomFormsAuthentication<UserCookie>.SignIn(LoginName, this, ApplicationSettingsFactory.ApplicationSettings.SessionTimeout);
        }

        public void Update()
        {
            if (ApplicationSettingsFactory.ApplicationSettings.ResetLoginCookieInterval <= (DateTime.Now - m_lastModifyDate).TotalMinutes)
            {
                m_lastModifyDate = DateTime.Now;
                Save();
            }
        }

        public void Remove()
        {
            CustomFormsAuthentication<UserCookie>.SignOut();
        }
    }
}
